﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms;
using System.IO;




namespace JumpingMan
{
    class Player
    {

        public int x;
        public int y;
        public string namn;       
        public int minutes;
        public int seconds;
        public int time;
        public Point direction;

        StreamWriter fin;
        //FileStream fin;
        

        public Player()
        {
            this.x = 0;
            this.y = 250;
            this.namn = "";
            this.seconds = 0;
            this.minutes = 0;
            
            this.direction = new Point(0, 0);
        }
        public void MoveMobToDirection()
        {
            this.x += direction.X;
            this.y += direction.Y;
            if (this.x > 450)
            {
                this.x = 0;
            }
            if (this.x < 0)
            {
                this.x = 450;
            }
            if (this.y < 0)
            {
                this.y = 400;
            }
            if (this.y > 400)
            {
                this.y = 0;
            }
        }
        public void MoveMob(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Up)
            {
                this.direction.Y = -1;
            }
            if (e.KeyCode == Keys.Down)
            {
                this.direction.Y = 1;
            }
            if (e.KeyCode == Keys.Right)
            {
                this.direction.X = 1;
            }
            if (e.KeyCode == Keys.Left)
            {
                this.direction.X = -1;
            }
        }
        public void DrawPlayer(Graphics imageGraphic)
        {
            Image olive = Image.FromFile(@"olive.jpg");
            imageGraphic.DrawImage(olive, this.x, this.y);
            //Rectangle rect = new Rectangle(this.x, this.y, 10, 10);
            //imageGraphic.FillRectangle(new SolidBrush(Color.Green), rect);
        }
        public bool CheckForCollision(ListofMobs listofMobs, Sound soundplayer, Label label)
        {
            for (int w = 0; w < listofMobs.mobs.Count; w++)
            {
               
                    for (int i = 0; i < 15; i++)
                    {
                        for (int g = 0; g < 15; g++)
                        {
                            if (this.x + i == listofMobs.mobs[w].x && this.y + g == listofMobs.mobs[w].y)
                            {
                                soundplayer.PlayShowMeTheMoney();
                                MessageBox.Show("EUROPE GOT YOU, SHOW THEM THE MONEY!");
                                this.WriteResultToFile(label);
                                return false;

                            }
                        }
                    }
                    for (int i = 0; i < 15; i++)
                    {
                        for (int g = 0; g < 15; g++)
                        {
                            if (listofMobs.mobs[w].x + i == this.x && listofMobs.mobs[w].y + g == this.y)
                            {
                                soundplayer.PlayShowMeTheMoney();
                                MessageBox.Show("EUROPE GOT YOU, SHOW THEM THE MONEY!");
                                this.WriteResultToFile(label);
                                return false;
                            }
                        }
                    }
                
            }
            return true;
        }
        public void WriteResultToFile(Label label)
        {
            fin = new StreamWriter(@"highscore.txt", true);

            
            string text = "";
            text = label.Text + " " + this.namn;
            fin.WriteLine(text);
            fin.Close();
        }
    
    
    }
}
